//
//  homeNewsViewController.m
//  GentlemanAnime
//
//  Created by dlios on 15-7-14.
//  Copyright (c) 2015年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "homeNewsViewController.h"
//#import "NewsDetailViewController.h"
#import "AFNetworking.h"
#import "MBProgressHUD.h"


@interface homeNewsViewController ()

@property(nonatomic,retain)MBProgressHUD *SearchDetailHUD;

@property(nonatomic, assign)BOOL isArchiver;
@property(nonatomic, retain)NSMutableArray *newsArr;

@end

@implementation homeNewsViewController

- (void)dealloc
{
    [_SearchDetailHUD release];
    [_newsID release];
    [_newsArr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.view.frame = [UIScreen mainScreen].bounds;
    
    UILabel *titlelebel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
    titlelebel.text = self.newsModel.title;
    titlelebel.font = [UIFont boldSystemFontOfSize:18];
    titlelebel.textAlignment = NSTextAlignmentCenter;
    titlelebel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = titlelebel;
    [titlelebel release];
    
    // 反归档
    [self fanGuiDang];
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    webView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:webView];
    
    // 返回按钮
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
    leftButton.frame = CGRectMake(0, 0, 60, 30);
    [leftButton setTitle:@"返回" forState:UIControlStateNormal];
    leftButton.imageEdgeInsets = UIEdgeInsetsMake(5, 0, 5, 40);
    [leftButton setImage:[UIImage imageNamed:@"单箭头"] forState:UIControlStateNormal];
    leftButton.titleLabel.font = [UIFont systemFontOfSize:16];
    leftButton.titleEdgeInsets = UIEdgeInsetsMake(0, - 20, 0, 0);
    leftButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [leftButton addTarget:self action:@selector(leftClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    
    
    // 小菊花
    self.SearchDetailHUD= [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.SearchDetailHUD.mode= MBProgressHUDModeIndeterminate;
    self.SearchDetailHUD.color = [UIColor colorWithRed:0.334 green:0.619 blue:1.000 alpha:1.000];
    
    NSString *strURL = [NSString stringWithFormat:@"http://www.manmi.me/?c=info&m=news_view&id=%@",self.newsID];
    
    
    NSURL *url = [NSURL URLWithString:strURL];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
    
    [webView release];
    //小菊花
    [self.SearchDetailHUD hide:YES];
}



#pragma mark 反归档
- (void)fanGuiDang
{
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 1, YES);
    NSString *sandBoxPath = sandBox[0];
    NSString *documentPath = [sandBoxPath stringByAppendingPathComponent:@"news.plist"];
    self.newsArr = [NSKeyedUnarchiver unarchiveObjectWithFile:documentPath];
    self.isArchiver = NO;
    if (self.newsArr == nil) {
        self.newsArr = [NSMutableArray array];
    }else{
        for (NewsTableViewModel *news in self.newsArr) {
            if ([news.Id isEqualToString:self.newsID]) {
                self.isArchiver = YES;
                break;
            }
        }
    }
}

#pragma mark 返回按钮
- (void)leftClick:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
